package com.byjh.api;


import com.byjh.app.domain.QuestionPracticeRecord;
import com.byjh.app.dto.AddPracticeDto;
import com.byjh.app.service.IChapterService;
import com.byjh.app.service.IQuestionPracticeRecordService;
import com.byjh.app.service.IQuestionService;
import com.byjh.common.core.controller.BaseController;
import com.byjh.common.core.domain.R;
import com.byjh.common.utils.SecurityUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

@RestController
@RequestMapping("/api/sequence")
public class SequenceApi extends BaseController {

    @Resource
    private IQuestionPracticeRecordService recordService;


    /**
     * 获取当前用户的练习题目顺序记录
     */
    @GetMapping("/getRecord")
    public R<QuestionPracticeRecord> getSequenceRecord() {
        Long userId = SecurityUtils.getUserId();
        return R.ok(recordService.selectQuestionPracticeRecordByUserId(userId));
    }



    /**
     * 添加练习题目顺序记录
     *
     * @return
     */
    @PostMapping("/addRecord")
    public R<String> addSequenceRecord(@RequestBody @Valid AddPracticeDto dto) {
        Long userId = SecurityUtils.getUserId();
        recordService.insertQuestionPracticeRecord(new QuestionPracticeRecord()
                .setUserId(userId)
                .setSubjectId(dto.getSubjectId())
                .setQuestionId(dto.getQuestionId())
                .setCurrent(dto.getCurrent()));
        return R.ok();
    }

}
